<!--title-->
<div class="mnav1">
	<div class="m_nav">
		<div class="nav_left">
			<em class="home_icon"><?=$this->sys_name?></em><span>&nbsp;&gt;&nbsp;</span><font><?=$this->title?></font>
		</div>
	</div>
</div>

<div class="content-table">
<div class="content-table-title"><?=$this->title?></div>
<br />
<?php if($this->msg):?>
<div class="replace"><?=$this->msg?></div>
<br />
<?php endif;?>
<div class="form-edit-task">

<?php
$total_qty = 0;

foreach($this->sku_info['base_info'] as $val)
{
	$total_qty += $val['quantity'];
}	
?>

<form action="/contracts/edit-contract-submit" method="post" name="form1" onsubmit="submitform(this);return false;">
<table border="1" width="100%">
	<tr>
		<td align="right">合同状态：</td>
		<td align="left">&nbsp;<select name="delivery_status">
			<?php foreach($this->delivery_statuses as $status_id => $status_name):?>
			<option value="<?=$status_id?>" <?php if($status_id==$this->contract_info['delivery_status']){echo "selected='selected'";}?>><?=$status_name?></option>
			<?php endforeach;?>
			</select>&nbsp;&nbsp;<button>更新状态</button>
		</td>
	</tr>
	<tr>
		<td align="right" width="30%">合同编号：</td>
		<td align="left">&nbsp;<?=$this->contract_info['contract_sid']?></td>
	</tr>
	<tr>
		<td align="right" width="30%">客户全称：</td>
		<td align="left">&nbsp;<?=$this->client_info['client_name']?></td>
	</tr>
	<?php if($this->client_info['additional_info']['brand_info']['str']):?>
	<tr>
		<td align="right" width="30%">品牌：</td>
		<td align="left">&nbsp;<?=$this->client_info['additional_info']['brand_info']['str']?></td>
	</tr>
	<?php endif;?>
	<?php if($this->client_info['additional_info']['channel_info']['str']):?>
	<tr>
		<td align="right" width="30%">渠道：</td>
		<td align="left">&nbsp;<?=$this->client_info['additional_info']['channel_info']['str']?></td>
	</tr>
	<?php endif;?>
	<?php if($this->client_info['additional_info']['factory_info']['str']):?>
	<tr>
		<td align="right" width="30%">厂商：</td>
		<td align="left">&nbsp;<?=$this->client_info['additional_info']['factory_info']['str']?></td>
	</tr>
	<?php endif;?>
	<tr>
		<td align="right">签约公司：</td>
		<td align="left">&nbsp;<?=$this->contract_info['signer_company_name']?$this->contract_info['signer_company_name']:$this->contract_info['client_name']?></td>
	</tr>
	<tr>
		<td align="right">乙方单位：</td>
		<td align="left">&nbsp;<?=$this->contract_info['owner_name']?></td>
	</tr>
	<tr>
		<td align="right" width="30%">销售顾问：</td>
		<td align="left">&nbsp;<?=$this->contract_info['sales_emp_name']?></td>
	</tr>
	<tr>
		<td align="right">起止日期：</td>
		<td align="left">&nbsp;<?=$this->contract_info['start_date']?> 至 <?=$this->contract_info['expired_date']?>
		</td>
	</tr>
	<tr>
		<td align="right">合同标准金额：</td>
		<td align="left">&nbsp;<?=$this->contract_info['contract_claim_amount']?></td>
	</tr>
	<tr>
		<td align="right">合同实际金额：</td>
		<td align="left">&nbsp;<?=$this->contract_info['contract_value']?></td>
	</tr>
	<tr>
		<td align="right">整单数量：</td>
		<td align="left">&nbsp;<?=$total_qty?></td>
	</tr>
	<tr>
		<td align="right">折扣：</td>
		<td align="left">&nbsp;<?=round($this->contract_info['receivable_value']/($this->contract_info['contract_claim_amount']*2)*100)."%"?></td>
	</tr>
	<tr>
		<td align="right">付款方式：</td>
		<td align="left">&nbsp;<?php if(1==$this->contract_info['pay_type']){echo "预付";}elseif(2==$this->contract_info['pay_type']){echo "后付";}elseif(3==$this->contract_info['pay_type']){echo "分期";}elseif(4==$this->contract_info['pay_type']){echo "免费";}?><?php if(2==$this->contract_info['pay_type']):?>&nbsp;&nbsp;&nbsp;&nbsp;(回款日期：<?=$this->contract_info['pay_date']?>)<?php endif;?></td>
	</tr>
	<tr>
		<td align="right">合同备注：</td>
		<td align="left">&nbsp;<?=$this->contract_info['tips']?"<font color='red'>".$this->contract_info['tips']."</font>":""?></td>
	</tr>
	<tr>
		<td align="right">审批状态：</td>
		<td align="left">&nbsp;<?php if($this->contract_info["allow_edit"]):?>驳回修改<?php else:?><?=$this->statuses[$this->contract_info['status']]?><?php endif;?></td>
	</tr>
	<tr>
		<td align="right">申请日期：</td>
		<td align="left">&nbsp;<?=substr($this->contract_info['ctime'],0,10)?></td>
	</tr>
	<tr>
		<td align="right">签约日期：</td>
		<td align="left">&nbsp;<?=$this->contract_info['sign_date']?></td>
	</tr>
	<tr>
		<td align="right">经销商明细：</td>
		<td align="left">&nbsp;<?=$this->contract_info['dealers_str']?></td>
	</tr>
</table>
<br />
<table border="1" width="100%">
	<tr>
		<th>经销商ID</th>
		<th>产品</th>
		<th>刊例单价</th>
		<th>数量</th>
		<th>刊例价</th>
		<th>标准售价</th>
		<th>实际售价</th>
		<th>服务期限</th>
		<th>托管平台</th>
	</tr>
	<?php foreach($this->sku_info['base_info'] as $val):?>
	<tr>
		<td><?=$val['dealer_id']?></td>
		<td><?=$val['sku_path']['path_name']?>
            <?php if($val['product_id'] == '2'):?>
                <br/><span style="color:red">汇销宝账号：<?=$val['hxb_account']?></span>
            <?php endif;?>
        </td>
		<td><?=$val['unit_price']?></td>
		<td><?=$val['quantity']?></td>
		<td><?=$val['rrp']?></td>
		<td><?=$val['claim_amount']?></td>
		<td><?=$val['actual_pay']?></td>
		<td><?=$val['start_date']?>至<?=$val['expired_date']?></td>
		<td><?=$this->sku_info['service_info']['str'][$val['cs_id']]?></td>
	</tr>
	<?php endforeach;?>
</table>
<br /><br />

<div align="center"><h2>财务区域</h2></div>
<br />
<input type="hidden" name="contract_id" value="<?=$this->contract_info['contract_id']?>" />
<table border="1" width="100%">
	<tr>
		<td align="right" width="30%">合同实际金额：</td>
		<td align="left">&nbsp;<?=$this->contract_info['contract_value']?></td>
	</tr>
	<tr>
		<td align="right">应收金额：</td>
		<td align="left">&nbsp;<?=$this->contract_info['receivable_value']?></td>
	</tr>
	<?php if($this->contract_info['receivable_value']==$this->contract_info['received_value']){$color="green";}else{$color="red";}?>
	<tr>
		<td align="right">已收金额：</td>
		<td align="left">&nbsp;<font color="<?=$color?>"><?=$this->contract_info['received_value']?></font></td>
	</tr>
	<tr>
		<td align="right">执行状态：</td>
		<td align="left">&nbsp;<?php if(2==$this->contract_info['launch_switcher']):?><font color='green'>已执行</font><?php elseif(1==$this->contract_info['launch_switcher']):?><font color='green'>已通知执行</font><?php else:?><font color='red'>未执行</font><?php endif;?></td>
	</tr>
</table>
<br />
<?php if("LEVEL-4" == $_SESSION['identity']['level']):?>
<table border="1" width="100%">
	<tr>
		<td align="center" colspan="5"><b>认款明细</b><?php if(in_array($this->contract_info['status'], array(2,3,4))):?>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/contracts/add-contract-log/contract_id/<?=$this->contract_info['contract_id']?>">【<u>添加认款记录</u>】</a><?php endif;?></td>
	</tr>
	<tr>
		<td align="center"><b>时间</b></td>
		<td align="center"><b>金额</b></td>
		<td align="center"><b>发票号码</b></td>
		<td align="center"><b>备注</b></td>
		<td align="center"><b>操作</b></td>
	</tr>
	<?php if($this->logs):?>
	<?php foreach($this->logs as $log):?>
	<tr>
		<td align="center"><?=$log['ctime']?></td>
		<td align="center"><?=$log['value']?></td>
		<td align="center"><?=$log['invoice']?></td>
		<td align="center"><?=$log['tips']?></td>
		<td align="center"><button onclick="LogOpt(<?=$log['lid']?>, 2)">删除</button></td>
	</tr>
	<?php endforeach;?>
	<?php endif;?>
</table>
<br />
<?php endif;?>
<table border="1" width="100%">
	<tr>
		<td align="center" colspan="3"><b>操作日志</b></td>
	</tr>
	<tr>
		<td align="center"><b>时间</b></td>
		<td align="center"><b>操作内容</b></td>
		<td align="center"><b>操作人</b></td>
	</tr>
	<?php if($this->action_logs):?>
	<?php foreach($this->action_logs as $log):?>
	<tr>
		<td align="center"><?=$log['ctime']?></td>
		<td align="center"><?=$log['contents']?></td>
		<td align="center"><?=$log['realName']?></td>
	</tr>
	<?php endforeach;?>
	<?php endif;?>
</table>
<br /><br />
<br /><br />
</form>
</div>
<br/><br/>
</div>

<script>
function num(th){
	th.value = th.value.replace(/[^\d\.]*$/g, '');
}

function submitform() 
{	
	form1.submit();
}

function LogOpt(lid)
{
	var msg = "确认删除此认款记录？您的操作将会被记录。";
	
	if (confirm(msg)==true){
			$.ajax({
				type: "post",
				url : "/ajax/del-contract-opt",
				dataType:'json',
				async:false,
				data: {
						'lid':lid
					  },
					success: function(json){
						if(json.result == 1) {
							window.location.href = "/contracts/edit-contract/contract_id/" + json.contract_id + "/msg/1";
						}else{
							window.location.href = "/contracts/edit-contract/contract_id/" + json.contract_id + "/msg/2";
						}
				}
			});
	}else{ 
		return false; 
	}
}
</script>
